package org.qpcr.community.project.model.entity;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import org.hswebframework.ezorm.rdb.mapping.annotation.ColumnType;
import org.hswebframework.ezorm.rdb.mapping.annotation.Comment;
import org.hswebframework.ezorm.rdb.mapping.annotation.DefaultValue;
import org.hswebframework.ezorm.rdb.mapping.annotation.JsonCodec;
import org.hswebframework.web.api.crud.entity.GenericEntity;
import org.hswebframework.web.crud.annotation.EnableEntityEvent;
import org.hswebframework.web.crud.generator.Generators;
import org.hswebframework.web.validator.CreateGroup;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import java.sql.JDBCType;
import java.util.Map;

@Getter
@Setter
@Table(name = "biz_data_back")
@Comment("出厂数据备份")
@EnableEntityEvent
public class DataBackUpEntity extends GenericEntity<String> {

    @Override
    @Id
    @Column(length = 64, updatable = false)
    @Schema(description = "ID")
    @GeneratedValue(generator = Generators.SNOW_FLAKE)
    @NotBlank(message = "ID不能为空", groups = CreateGroup.class)
    public String getId() {
        return super.getId();
    }

    @Column(name = "name", length = 150)
    @Schema(description = "文件名称")
    private String name;

    @Column(name = "type", length = 1)
    @Schema(description = "类型：0 pcr程序 1模块程序")
    private int type;

    @Column(name = "file_id", length = 64)
    @Schema(description = "附件id")
    public String fileId;

    @Column(name = "configuration")
    @JsonCodec
    @Schema(description = "路径和配置")
    @ColumnType(jdbcType = JDBCType.LONGVARCHAR, javaType = String.class)
    private Map<String, Object> configuration;



    @Column(name = "creator_id", updatable = false)
    @Schema(
        description = "创建者ID(只读)"
        , accessMode = Schema.AccessMode.READ_ONLY
    )
    private String creatorId;

    @Column(name = "creator_user_name", updatable = false)
    @Schema(
        description = "创建者账号(只读)"
        , accessMode = Schema.AccessMode.READ_ONLY
    )
    private String creatorUserName;

    @Column(name = "creator_name", updatable = false)
    @Schema(
        description = "创建者名称(只读)"
        , accessMode = Schema.AccessMode.READ_ONLY
    )
    private String creatorName;


    @Column(name = "create_time", updatable = false)
    @DefaultValue(generator = Generators.CURRENT_TIME)
    @Schema(
        description = "创建时间(只读)"
        , accessMode = Schema.AccessMode.READ_ONLY
    )
    private Long createTime;

}
